import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/on_duty_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/personnel_statistics_entity.dart';
import 'package:get/get.dart';

class PersonnelManagementController extends GetxController {
  ///人员信息
  PersonnelStatisticsEntity peopleEntity = PersonnelStatisticsEntity();

  ///值班统计
  OnDutyEntity dutyEntity = OnDutyEntity();

  List<String> personnelList = [
    '主要负责人',
    '分管安全负责人',
    '企业在册从业人员',
    '专职安全人员',
    '注册安全工程师',
    '特种作业',
  ];

  Map<String, int> peopleMap = {};

  @override
  void onInit() {
    super.onInit();
    getPeopleDetailsData();
    getOnDutyData();
  }


  /// 获取人员统计数据
  void getPeopleDetailsData() async {
    // 获取详情接口
    final res = await HttpUtil().generateGetRequest<PersonnelStatisticsEntity>(Interface.personnelStatistics).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        peopleEntity = result.data!;
        peopleMap['主要负责人'] = peopleEntity.personInChargeNum!;
        peopleMap['分管安全负责人'] = peopleEntity.personInChargeOfSafety!;
        peopleMap['企业在册从业人员'] = peopleEntity.registeredEmployeesOfEnterprises!;
        peopleMap['专职安全人员'] = peopleEntity.dedicatedSafetyPersonnel!;
        peopleMap['注册安全工程师'] = peopleEntity.certifiedSafetyEngineer!;
        peopleMap['特种作业'] = peopleEntity.specialOperations!;
      }
      update();
    });
  }

  /// 获取值班统计数据
  void getOnDutyData() async {
    // 获取详情接口
    final res = await HttpUtil().generatePostRequest<OnDutyEntity>(Interface.getOnDutyApp).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        dutyEntity = result.data!;
      }
      update();
    });
  }
}
